package org.jeecg.modules.online.desform.constant;

import org.jeecg.common.util.oConvertUtils;

/**
 * ElasticSearch的字段类型
 */
public enum EsTypes {

    STRING("string", "字符串类型"),
    TEXT("text", "字符串类型"),
    KEYWORD("keyword", "字符串类型"),
    INTEGER("integer", "整数类型"),
    LONG("long", "整数类型"),
    SHORT("short", "整数类型"),
    BYTE("byte", "整数类型"),
    DOUBLE("double", "浮点类型"),
    FLOAT("float", "浮点类型"),
    HALF_FLOAT("half_float", "浮点类型"),
    SCALED_FLOAT("scaled_float", "浮点类型"),
    BOOLEAN("boolean", "逻辑类型"),
    DATE("date", "日期类型");

    private String type;
    private String name;

    EsTypes(String type, String name) {
        this.type = type;
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public String getName() {
        return name;
    }

    /**
     * 比较两个值是否相等
     */
    public boolean compare(Object value) {
        EsTypes type = EsTypes.getByValue(value);
        return type == this;
    }

    public static EsTypes getByValue(Object value) {
        if (oConvertUtils.isEmpty(value)) {
            return null;
        }
        return getByValue(value.toString());
    }

    public static EsTypes getByValue(String value) {
        if (oConvertUtils.isEmpty(value)) {
            return null;
        }
        for (EsTypes val : values()) {
            if (val.getType().toLowerCase().equals(value.toLowerCase())) {
                return val;
            }
        }
        return null;
    }

}
